import React, { Component } from 'react';
import { View, Text, StyleSheet, ScrollView, Image, Platform, TextInput, TouchableOpacity } from 'react-native';
import { Toast } from 'antd-mobile-rn';

export default class UpdateAddress extends Component {


    static navigationOptions = ({ navigation }) => {

        const onSaveClick = navigation.getParam("onSaveClick",()=>{})

        return {
            title: "修改考试地点",
            headerLeft: (
                <TouchableOpacity style={{ marginLeft: 20 }} onPress={() => {
                    navigation.goBack();
                }}>
                    <Text>取消</Text>
                </TouchableOpacity>
            ),
            headerRight: (
                <TouchableOpacity style={{ marginRight: 20 }} onPress={()=>{onSaveClick()}}>
                    <Text style={{ color: "#00b7A5" }}>完成</Text>
                </TouchableOpacity>
            ),

        }

    }
    state = {
        nickname: ""
    }

    componentDidMount() {
        const { navigation } = this.props;
        this.setState({
            nickname: navigation.getParam("nickname", "")
        });
        const back = navigation.getParam("back",()=>{});
        navigation.setParams({
            onSaveClick:()=>{
                const {nickname} = this.state;
                if(!nickname){
                    Toast.info("不能为空");
                    return;
                }

                back(nickname);
                navigation.goBack();
            }
        })
    }

    render() {
        return (
            <View style={{
                flex: 1,
                backgroundColor: "#e6e6e6"
            }}>
                <View style={{
                    height: 48,
                    backgroundColor: "#fff",
                    marginTop: 10,
                    alignItems: "center",

                }}>
                    <TextInput
                        value={this.state.nickname}
                        autoFocus={true}
                        style={{
                            width: "100%",
                            paddingLeft: 20,
                            height: 48


                        }}
                        onChangeText={(value) => {
                            this.setState({
                                nickname: value
                            })
                        }}
                        returnKeyLabel={"确定"}
                        returnKeyType={"done"}

                    ></TextInput>
                </View>
            </View>
        )
    }


}